package com.qq.spirit.model;

import java.util.concurrent.atomic.AtomicBoolean;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider;
import com.gargoylesoftware.htmlunit.WebClient;
import com.qq.spirit.LoginTask;
import com.qq.spirit.TaskManager;
import com.qq.spirit.UserState;

public class UserData
{
	private String username = "";
	private String password = "";

	private XmlNodeData allPlayInfo = null;

	// 宴会对象

	private XmlNodeData dinnerInfo = null;

	// 征收对象
	private XmlNodeData imposeInfo = null;

	/**
	 * 攻击结果对象
	 */
	private XmlNodeData playerbattleinfo = null;

	/**
	 * 开发区结果对象
	 */
	private XmlNodeData kfzonestate = null;
	/**
	 * 游戏昵称
	 */
	private String gamename = "";

	private int refineTimes;

	private AtomicBoolean isInRefine = new AtomicBoolean(false);

	public int getRefineTimes()
	{
		return refineTimes;
	}

	public void setRefineTimes(int refineTimes)
	{
		this.refineTimes = refineTimes;
	}

	public AtomicBoolean getIsInRefine()
	{
		return isInRefine;
	}

	public void setIsInRefine(AtomicBoolean isInRefine)
	{
		this.isInRefine = isInRefine;
	}

	public XmlNodeData getPlayerbattleinfo()
	{
		return playerbattleinfo;
	}

	public void setPlayerbattleinfo(XmlNodeData playerbattleinfo)
	{
		this.playerbattleinfo = playerbattleinfo;
	}

	public XmlNodeData getKfzonestate()
	{
		return kfzonestate;
	}

	public void setKfzonestate(XmlNodeData kfzonestate)
	{
		this.kfzonestate = kfzonestate;
	}

	// 用户的HttpClient对象
	private WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_8, "proxy.tencent.com", 8080);
	// 用户登录Session
	private UserState userState = UserState.INIT;

	public XmlNodeData getImposeInfo()
	{
		return imposeInfo;
	}

	public String getGamename()
	{
		return gamename;
	}

	public void setGamename(String gamename)
	{
		this.gamename = gamename;
	}

	public void setImposeInfo(XmlNodeData imposeInfo)
	{
		this.imposeInfo = imposeInfo;
	}

	public XmlNodeData getDinnerInfo()
	{
		return dinnerInfo;
	}

	public void setDinnerInfo(XmlNodeData dinnerInfo)
	{
		this.dinnerInfo = dinnerInfo;
	}

	public XmlNodeData getAllPlayInfo()
	{
		if (allPlayInfo == null)
		{
			TaskManager.addTask(new LoginTask(username, null));
		}
		return allPlayInfo;
	}

	public WebClient getClient()
	{
		return webClient;
	}

	public void setAllPlayInfo(XmlNodeData allPlayInfo)
	{
		this.allPlayInfo = allPlayInfo;
		gamename = XmlDataUtil.getNodeData(allPlayInfo, "results.player.playername");
	}

	public UserData(String username, String password)
	{
		super();
		this.username = username;
		this.password = password;
		// webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
		DefaultCredentialsProvider credentialsProvider = (DefaultCredentialsProvider) webClient.getCredentialsProvider();
		credentialsProvider.addCredentials("beedoorwei", "959624Xl");
		webClient.setJavaScriptEnabled(false);
		webClient.setCssEnabled(false);
	}

	public String getUsername()
	{
		return username;
	}

	public void setUsername(String username)
	{
		this.username = username;
	}

	public String getPassword()
	{
		return password;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	public UserState getUserState()
	{
		return userState;
	}

	public void setUserState(UserState userState)
	{
		this.userState = userState;
	}
}
